package com.wn.sk.product.tast;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author yellow Docter
 * @date 2022 -11-08
 * @desc
 */
public class PoolApp {

    public static void main(String[] args) throws InterruptedException {

        // 创建 ScheduledThreadPool 线程池
        //eureka 和 nacos 中的源码
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(10);
        System.out.println("schedule 方法添加任务：" + LocalDateTime.now());
        threadPool.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行 schedule 方法：" + LocalDateTime.now());
            }
        },2L, 3L, TimeUnit.SECONDS); // 3s 之后执行

    }

}
